////////

#if 1
#include <stdio.h>
#include <stdint.h>

#include <que_struct_u16.h>

void InitItmU16Que(defU16Que *q)
{
	q->front = q->rear = 0;
}
//static int getRtcMaxCount(void);
static void entryItmU16Que(defU16Que *q,uint16_t e);
//static void entryItmU16Que(defU16Que *q,uint16_t e);
static int exitItmU16Que(defU16Que *q,uint16_t *e);

static int getItmU16Que(defU16Que *q,uint16_t i,uint16_t* v);
static int getLenU16Que(defU16Que *q);

static int getMaxModQue(defU16Que *q);

static int getMaxModQue(defU16Que *q)
{
	return q->getQueCount()+1;
}

static void entryItmU16Que(defU16Que *q,uint16_t e)
{
	if((q->rear + 1) % getMaxModQue(q) == q->front)
	{
		q->front = (q->front + 1) % getMaxModQue(q);
	}
	q->pData[q->rear] = e;
	q->rear = (q->rear + 1) % getMaxModQue(q);
}

static int exitItmU16Que(defU16Que *q,uint16_t *e)
{
	if(q->rear == q->front)
		return -1;
	*e = q->pData[q->front];
	q->front = (q->front + 1) % getMaxModQue(q);
	return 0;
}
static int getItmU16Que(defU16Que *q,uint16_t i,uint16_t* v)
{
	uint16_t len;
	if(q->rear == q->front)
		return -1;
	len = (q->rear - q->front + getMaxModQue(q)) % getMaxModQue(q);
	if(len <= i) return -1;
	*v = q->pData[(q->front+i)% getMaxModQue(q)];
	return 0;
}
static int getLenU16Que(defU16Que *q)
{
	return (q->rear - q->front + getMaxModQue(q)) % getMaxModQue(q);
}

//const int CRtcMaxSIZE=5;
#define CRtcMaxSIZE 5
//static const  uint16_t CRtcMaxSIZE=5;
//const uint16_t CRtcMaxSIZE=5;
//uint16_t const CRtcMaxSIZE=5;

static uint16_t RtcData[CRtcMaxSIZE];

static int getRtcMaxCount(void)
{
    return CRtcMaxSIZE;
}

static defU16Que RtcQue=
{
    //.count=CRtcMaxSIZE,
    .front=0,
    .rear=0,
    .getQueCount=getRtcMaxCount,
    .push_back=entryItmU16Que,
    .pop_front=exitItmU16Que,
    .get_index=getItmU16Que,
    .length=getLenU16Que,
    .pData=RtcData
};

defU16Que* getRtcQuePt(void)
{
	printf("%s,%s,%d,%ld;%ld\r\n", __FILE__,__func__,__LINE__, sizeof(RtcData) ,sizeof(RtcQue) );
    return &RtcQue;
}

#endif



